#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
主题:查找两字典的相同点
问题: 怎样在两个字典中寻寻找相同点（比如相同的键、相同的值等等）？
提示 : 
"""

a = {
    'x': 1,
    'y': 2,
    'z': 3
}
print(f"{a = }")

b = {
    'w': 10,
    'x': 11,
    'y': 2
}
print(f"{b = }")

def recipe1():
    # 查找相同的健
    common_key = a.keys() & b.keys()
    print(f"{common_key = }")

    # Find keys in a that are not in b
    diff_key = a.keys() - b.keys()
    print(f"{diff_key = }")

    # Find (key,value) pairs in common
    common = a.items() & b.items()
    print(f"{common = }")

    # Find (key,value) in a that are not in b
    diff = a.items() - b.items()
    print(f"{diff = }")

def recipe2():
    '''操作也可以用于修改或者过滤字典元素'''
    # Make a new dictionary with certain keys removed
    c = {key:a[key] for key in a.keys() - {'z', 'w'}}
    print(f"{c = }")

def main():
    print('recipe1'.center(20, '*'))
    recipe1()
    print('recipe2'.center(20, '*'))
    recipe2()    


if __name__ == '__main__':
    main()
